//
//  KZHomeProductCell.swift
//  BoyeStore
//
//  Created by 朱凯 on 2018/6/23.
//  Copyright © 2018年 itboye. All rights reserved.
//

import UIKit

class KZHomeProductCell: UICollectionViewCell {
    
    let iconView = UIImageView()
    let nameLabel = UILabel()       // 名字
    let priceLabel = UILabel()      // 现价
    let oldPriceLabel = UILabel()   // 原价
    let noteLabel = UILabel()       // 备注
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

// MARK: ------ 创建ui
extension KZHomeProductCell {
    
    private func setupUI() {
        
        contentView.backgroundColor = UIColor.white
        contentView.layer.cornerRadius = 4
        contentView.layer.masksToBounds = true
        
        
        contentView.addSubview(iconView)
        iconView.image = kDefaultImage
        iconView.snp.makeConstraints { (m) in
            m.left.top.right.equalTo(0)
            m.height.equalTo(iconView.snp.width)
        }
        
        nameLabel.textColor = UIColor.black
        nameLabel.numberOfLines = 2
        nameLabel.textAlignment = .left
        nameLabel.text = "智能心率手环、手表(连接手机)qqqqqqqqqqqqq"
        nameLabel.font = UIFont.systemFont(ofSize: 14)
        contentView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (m) in
            m.left.equalTo(5)
            m.right.equalTo(-5)
            m.top.equalTo(iconView.snp.bottom)
            m.height.equalTo(40)
        }
        
        priceLabel.textColor = kThemeColor
        priceLabel.textAlignment = .left
        priceLabel.text = "￥125.0"
        priceLabel.font = UIFont.systemFont(ofSize: 14)
        contentView.addSubview(priceLabel)
        priceLabel.snp.makeConstraints { (m) in
            m.left.equalTo(5)
            m.height.equalTo(20)
            m.top.equalTo(nameLabel.snp.bottom)
        }
        
        oldPriceLabel.textColor = UIColor.lightGray
        oldPriceLabel.textAlignment = .left
        oldPriceLabel.text = "￥188.0"
        oldPriceLabel.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(oldPriceLabel)
        oldPriceLabel.snp.makeConstraints { (m) in
            m.left.equalTo(priceLabel.snp.right).offset(5)
            m.bottom.height.equalTo(priceLabel)
        }
        oldPriceLabel.attributedText = oldPriceLabel.text?.attrubutesString(attrubutes: [NSAttributedStringKey.strikethroughStyle: 2])
        
        noteLabel.textColor = kThemeColor
        noteLabel.adjustsFontSizeToFitWidth = true
        noteLabel.textAlignment = .left
        noteLabel.text = "本次优惠仅限三天，立即下单更有优惠"
        noteLabel.font = UIFont.systemFont(ofSize: 10)
        contentView.addSubview(noteLabel)
        noteLabel.snp.makeConstraints { (m) in
            m.left.equalTo(5)
            m.right.equalTo(-5)
            m.height.equalTo(20)
            m.top.equalTo(priceLabel.snp.bottom)
        }
        
    }
}
